<?php
// StyleManager.php

// 处理文件上传的逻辑
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['styleFile'])) {
    $uploadDir = './'; // 设置上传目录
    $uploadFile = $uploadDir . basename($_FILES['styleFile']['name']);

    // 检查文件名是否为 style.php
    if (basename($_FILES['styleFile']['name']) !== 'style.php') {
        echo "<p class='error'>文件名称必须为 style.php。</p>";
    } else {
        // 检查文件是否已经存在，如果存在则替换
        if (file_exists($uploadFile)) {
            unlink($uploadFile); // 删除旧文件
        }

        if (move_uploaded_file($_FILES['styleFile']['tmp_name'], $uploadFile)) {
            echo "<p class='success'>文件 " . htmlspecialchars(basename($_FILES['styleFile']['name'])) . " 已成功上传。</p>";
        } else {
            echo "<p class='error'>文件上传失败。</p>";
        }
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>样式管理</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
            text-align: center;
        }
        h1 {
            margin-bottom: 20px;
            color: #333;
        }
        form {
            display: flex;
            flex-direction: column;
        }
        label {
            margin-bottom: 5px;
            color: #555;
        }
        input[type="file"],
        input[type="submit"] {
            margin-bottom: 10px;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        input[type="submit"] {
            background-color: #007bff;
            color: #fff;
            border: none;
            cursor: pointer;
        }
        input[type="submit"]:hover {
            background-color: #0056b3;
        }
        .error {
            color: #ff0000;
            margin-top: 10px;
        }
        .success {
            color: #28a745;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>样式管理</h1>
        <form action="" method="post" enctype="multipart/form-data">
            <label for="styleFile">选择要上传的样式文件:</label>
            <input type="file" name="styleFile" id="styleFile" accept=".php">
            <input type="submit" value="上传文件">
        </form>
    </div>
</body>
</html>
